from pydantic import BaseModel, Field, ConfigDict
from typing import Generic, Optional, TypeVar


_T = TypeVar("_T")


class BaseSchema(BaseModel):
    model_config = ConfigDict(extra='ignore')


class BaseApiOut(BaseSchema, Generic[_T]):
    status: Optional[int] = 0
    code: Optional[int] = 0
    message: Optional[str] = "Success"
    data: Optional[_T] = None


class PageParams(BaseSchema):
    page: int = Field(1, description='分页页码,默认1 第一页')
    pageSize: int = Field(20, description='分页每页显示数量,默认20条一页')


class Paginate(BaseSchema):
    total: Optional[int] = Field(0, description='总数量')
    count: Optional[int] = Field(0, description='当前页计数')
    last_page: Optional[int] = Field(0, description='最后一页页码')
    current_page: Optional[int] = Field(0, description='当前页页码')
    next_page: Optional[int] = Field(0, description='下一页页码')
    previous_page: Optional[int] = Field(0, description='上一页页码')


class PaginateMeta(BaseSchema):
    meta: Optional[Paginate] = None


class BaseApiListOut(BaseApiOut, BaseSchema, Generic[_T]):
    data: Optional[_T] = None
    meta: Optional[Paginate | None] = None
